/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package br.com.menosehmais.framework.presentation;

import java.util.ArrayList;
import java.util.List;
import org.dozer.DozerBeanMapper;
import org.dozer.Mapper;

/**
 *
 * @author Rafael Quintino
 */
public class RestResponse<T>{
    
    private boolean success;
    private String message;
    private T object;
    private List<T> list;

    public RestResponse()
    {
        message = "error";
        success = false;
    }

    public RestResponse(boolean success, String message)
    {
        this.message = message;
        this.success = success;
    }

    public RestResponse(boolean success, T obj) {
        this.success = success;

        Mapper mapper = new DozerBeanMapper();
        this.object = (T) mapper.map(obj, obj.getClass());
    }

    public RestResponse(boolean success, List<T> list){
        this.success = success;

        this.list = new ArrayList<T>();
        for( Object obj : list){
            Mapper mapper = new DozerBeanMapper();
            this.getList().add( (T) mapper.map(obj, this.object.getClass()) );
        }
    }

    public boolean isSuccess() {
        return success;
    }

    public void setSuccess(boolean success) {
        this.success = success;
    }

    public String getMessage() {
        return message;
    }

    public void setMessage(String message) {
        this.message = message;
    }

    public T getObject() {
        return object;
    }

    public void setObject(T object) {
        this.object = object;
    }

    public final List<T> getList() {
        return list;
    }

    public void setList(List<T> list) {
        this.list = list;
    }
    
}
